<?php
/**
*	模块字段
*/
namespace Rainrock\Framework\kernel\core;



class ModuleFields{
	
	public static function get($fields='')
	{
		$obj = new ModuleFields();
		return $obj->setFields($fields);
	}
	
	private $name = '' ,$fields = '' ,$type = '',$sm = '',$dev='',$data='',$fieldstype='text',$align='center',$width='',$zdsm='',$dbtype='';
	
	private $islu = 1, $islb = 1,$isfields = 1, $len = 0, $isbt = 0, $iszs = 1,$isss=1,$ispx=0,$isonly=0,$iseditlx=0,$isjm=0;
	
	public function setFields($fields)
	{
		$this->fields = $fields;
		return $this;
	}
	
	public function setName($name)
	{
		$this->name = $name;
		return $this;
	}
	
	public function setZdsm($zdsm)
	{
		$this->zdsm = $zdsm;
		return $this;
	}
	
	public function setIseditlx($iseditlx)
	{
		$this->iseditlx = $iseditlx;
		return $this;
	}
	
	public function setIsjm($isjm)
	{
		$this->isjm = $isjm;
		return $this;
	}
	
	public function setWidth($width)
	{
		if($width && is_numeric($width))$width = ''.$width.'px';
		$this->width = $width;
		return $this;
	}
	
	public function setType($type)
	{
		$type 		= strtolower($type);
		$this->type = $type;
		if($type=='datetime' || $type=='date')$this->setDev(null);
		if($type=='int')$this->setLen(11);
		if($type=='bigint')$this->setLen(20);
		if($this->len==0 && $type=='varchar')$this->setLen(50);
		return $this;
	}
	
	public function setLen($len)
	{
		$this->len = $len;
		return $this;
	}
	
	public function setDev($dev)
	{
		$this->dev = $dev;
		return $this;
	}
	
	public function setAlign($align)
	{
		$this->align = $align;
		return $this;
	}
	
	public function setFieldstype($fieldstype)
	{
		$this->fieldstype = $fieldstype;
		return $this;
	}
	
	public function setSm($sm)
	{
		$this->sm = $sm;
		return $this;
	}
	
	public function setData($data)
	{
		$this->data = $data;
		return $this;
	}
	
	public function setIslu($islu)
	{
		$this->islu = $islu;
		return $this;
	}
	
	public function setIslb($islb)
	{
		$this->islb = $islb;
		return $this;
	}
	
	public function setIsbt($isbt)
	{
		$this->isbt = $isbt;
		return $this;
	}
	
	public function setIszs($iszs)
	{
		$this->iszs = $iszs;
		return $this;
	}
	
	public function setIsss($isss)
	{
		$this->isss = $isss;
		return $this;
	}
	
	public function setIspx($ispx)
	{
		$this->ispx = $ispx;
		return $this;
	}
	
	public function setIsfields($isfields)
	{
		$this->isfields = $isfields;
		return $this;
	}
	
	public function setIsonly($isonly)
	{
		$this->isonly = $isonly;
		return $this;
	}
	
	public function setDbtype($dbtype)
	{
		$this->dbtype = $dbtype;
		return $this;
	}
	
	public function getFields()
	{
		$dbtype = $this->dbtype;
		if(!$dbtype){
			$dbtype = $this->type;
			if($this->len > 0)$dbtype .= '('.$this->len.')';
		}
		return array(
			'name' 	=> $this->name,
			'fields' => $this->fields,
			'type' 	=> $this->type,
			'dbtype'=> $dbtype,
			'len' 	=> $this->len,
			'sm' 	=> $this->sm,
			'dev' 	=> $this->dev,
			'data' 	=> $this->data,
			'align' => $this->align,
			'islu' 	=> $this->islu,
			'islb' 	=> $this->islb,
			'isbt' 	=> $this->isbt,
			'iszs' 	=> $this->iszs,
			'isss' 	=> $this->isss,
			'ispx' 	=> $this->ispx,
			'isjm' 	=> $this->isjm,
			'zdsm' 	=> $this->zdsm,
			'iseditlx' 	=> $this->iseditlx,
			'width' 	=> $this->width,
			'isonly' 	=> $this->isonly,
			'isfields' 		=> $this->isfields,
			'fieldstype' 	=> $this->fieldstype,
		);
	}
}